<script type="text/javascript">
	cotCanHien[0] = 3;
</script>
<?php include "../scripts/editor.php"?>
<h2><strong>Gửi E-mail khách hàng</strong></h2>
<?php
$khachhang = new khachhangbs();
$danhsach = $khachhang->LayDanhSach();
?>
<form enctype="multipart/form-data" name="formgui"
	action="index.php?do=guiemailkhachhang_xuly" method="post"
	onsubmit="return checkManageLinkForm(this);">
	<table id="rounded-corner" class="display" summary="Gửi E-mail khách hàng" style="width: 945px">
		<thead>
			<tr>
				<th scope="col" class="rounded"><input type="checkbox" name="master" onclick="chon()" /></th>
				<th scope="col" class="rounded">Họ tên</th>
				<th scope="col" class="rounded">E-mail</th>
				<th scope="col" class="rounded">Địa bàn</th>
			</tr>
		</thead>
		<tfoot>
	        <tr>
	           	<th>Chọn</th>
	            <th>Họ tên</th>
	            <th>E-mail</th>
	            <th>Địa bàn</th>       
	       	</tr>
	    </tfoot>
	    <tbody>
		<?php
		for($i = 0; $i < ($danhsach == false ? 0 : count($danhsach)); $i++)
		{
			$HoTen = $danhsach[$i]["Ho"] . " " . $danhsach[$i]["Ten"];
			$MaDiaBan = $danhsach[$i]["MaDiaBan"];
			$diaban = new diabanbs();
			$diaban->MaDiaBan = $MaDiaBan;
			$dsdiaban = $diaban->LayDanhSach();
			echo "<tr>";
				echo "<td><input type='checkbox' name ='{$danhsach[$i]["MaKH"]}'></td>";
				echo "<td>{$HoTen}</td>";
				echo "<td>{$danhsach[$i]["Email"]}</td>";
				echo "<td>{$dsdiaban[0]["TenDiaBan"]}</td>";
			echo "</tr>";
		}
		?>
		</tbody>
	</table>
	<br/>
	<br/>
	<h2><strong>Nội dung Email</strong></h2>
	<table style="width: 850px;height:20px;">
		<tr>
			<td style="padding-top:10px;">Tiêu đề &nbsp<span class="requirefield">*</span></td>
			<td style="padding-top:10px;"><input class="txt" type="text" size="100" name="tieude" /> </td>
		</tr>
		<tr>
			<td style="padding-top:10px;">Nội dung &nbsp<span class="requirefield">*</span></td>
			<td style="padding-top:10px;"><textarea rows="20" cols="36" id="noidung"
					name="noidung"></textarea> 
        	<?php KhoiTaoEditor("noidung", 250); ?> 
        </td>
		</tr>
		<tr>
			<td style="padding-top:10px;">Đính kèm:</td>
			<td style="padding-top:10px;"><input type="file" name="TapTin" /></td>
		</tr>
		<tr>
			<td colspan="2" align="center"><input class="button small blue"
				type="submit" name="submit" id="submit" value="Gửi E-mail" /></td>
		</tr>
		<p class="requirefields">(*): Các trường bắt buộc phải có.</p>
	</table>
</form>
<br/>
<?php
	if(isset($_SESSION["GuiEmailKhachHang"]))
	{
		echo $_SESSION["GuiEmailKhachHang"];
		unset($_SESSION["GuiEmailKhachHang"]);
	}
?>
<script type="text/javascript">
        function chon()
        {
                var masterChecked = document.formgui.master.checked;
                
                for(var i=1; i<=document.formgui.elements.length;i++)
                {
                        if(document.formgui.elements[i].type=="checkbox")
                                document.formgui.elements[i].checked = masterChecked;
                }
        
        }
        function checkManageLinkForm(frm)
        {
            if(frm.tieude.value=="")
            {
            	alert('Bạn chưa nhập tiêu đề!');
            	frm.tieude.focus();
            	return false;
            }
            var editorText = CKEDITOR.instances.noidung.getData();
       	    if(editorText=="")
            {
            	alert('Bạn chưa nhập nội dung!');
            	frm.noidung.focus();
            	return false;
            }
            return true;
        }
 </script>